identify OLE-position in object

Hello,
I wrote a script, that replaces a whole bunch of variables (named in a list) in a module.
The problem are the OLEs. The replacing is very slow, when a OLE is in a object. So I want to identyfy a OLE in a object, cut it out, make the replacements and out it back where it was.
How can I do that? Or has someone a better idea?
Thanks a lot...
Mr.Ferrari - Mon Sep 13 09:08:30 EDT 2010

Re: identify OLE-position in object
Mathias Mamsch - Tue Sep 14 13:44:07 EDT 2010

Hmm you are right, it IS really slow :-) Maybe you can optimize your replace code to be faster, by explicitly checking for "{\object" or "{\pict" phrases, then search their ending by finding an approriate "}" using two regular expressions:

The example code below does a loop over all characters of the buffer, thereby skipping OLE objects ... Hope this helps, regards, Mathias
 

pragma runLim, 10000
 
Regexp reObj = regexp "({\\\\object)|({\\\\pict)"
Regexp reBrace = regexp "([{}])"
 
Buffer b = create(); 
b = richTextWithOle (current Object)."Object Text"
 
// print tempStringOf b
 
// halt
 
int pos = 0; 
int iLen = length b
int oleStart = 0
int oleEnd   = 0 
 
Buffer result = create() 
int nextOle = -1
 
while (pos < iLen) {
   if (nextOle < pos) {
    // find the next ole object
        if ( search (reObj, b, pos) ) {
                oleStart = oleStart + start 0
                int braceLevel = 1
                oleEnd = oleStart+1
                print "Searching End of OLE from:" oleStart "\n"
                while (braceLevel > 0) {
                        if ( search (reBrace, b, oleEnd) ) {
                                string found = b[oleEnd+(start 0):oleEnd+(end 0)]
                                print "Found brace at:" (start 0) "(" found ")\n"
                                oleEnd = (end 0)+1+oleEnd
                                print "oleEnd:" (oleEnd) "-" found "\n"
                                if found == "{" then braceLevel++
                                if found == "}" then braceLevel--                          
                        } else break
                }            
                nextOle = oleStart
        } else { nextOle = iLen + 1 }
        print "Found OLE object: " oleStart "\n"
   }
   // skip ole object
   if (nextOle == pos) { 
        pos = oleEnd; continue
        print "Skipping OLE object: " oleEnd "\n"
   }
 
   // your replace code here: 
   pos ++
}

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: identify OLE-position in object
Mr.Ferrari - Tue Oct 05 09:01:07 EDT 2010

Mathias Mamsch - Tue Sep 14 13:44:07 EDT 2010

Hmm you are right, it IS really slow :-) Maybe you can optimize your replace code to be faster, by explicitly checking for "{\object" or "{\pict" phrases, then search their ending by finding an approriate "}" using two regular expressions:

The example code below does a loop over all characters of the buffer, thereby skipping OLE objects ... Hope this helps, regards, Mathias
 

pragma runLim, 10000
 
Regexp reObj = regexp "({\\\\object)|({\\\\pict)"
Regexp reBrace = regexp "([{}])"
 
Buffer b = create(); 
b = richTextWithOle (current Object)."Object Text"
 
// print tempStringOf b
 
// halt
 
int pos = 0; 
int iLen = length b
int oleStart = 0
int oleEnd   = 0 
 
Buffer result = create() 
int nextOle = -1
 
while (pos < iLen) {
   if (nextOle < pos) {
    // find the next ole object
        if ( search (reObj, b, pos) ) {
                oleStart = oleStart + start 0
                int braceLevel = 1
                oleEnd = oleStart+1
                print "Searching End of OLE from:" oleStart "\n"
                while (braceLevel > 0) {
                        if ( search (reBrace, b, oleEnd) ) {
                                string found = b[oleEnd+(start 0):oleEnd+(end 0)]
                                print "Found brace at:" (start 0) "(" found ")\n"
                                oleEnd = (end 0)+1+oleEnd
                                print "oleEnd:" (oleEnd) "-" found "\n"
                                if found == "{" then braceLevel++
                                if found == "}" then braceLevel--                          
                        } else break
                }            
                nextOle = oleStart
        } else { nextOle = iLen + 1 }
        print "Found OLE object: " oleStart "\n"
   }
   // skip ole object
   if (nextOle == pos) { 
        pos = oleEnd; continue
        print "Skipping OLE object: " oleEnd "\n"
   }
 
   // your replace code here: 
   pos ++
}

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Hey,
thanks for your comment... I am still trying... :-)

Re: identify OLE-position in object
Mr.Ferrari - Wed Oct 06 09:43:12 EDT 2010

Mathias Mamsch - Tue Sep 14 13:44:07 EDT 2010

Hmm you are right, it IS really slow :-) Maybe you can optimize your replace code to be faster, by explicitly checking for "{\object" or "{\pict" phrases, then search their ending by finding an approriate "}" using two regular expressions:

The example code below does a loop over all characters of the buffer, thereby skipping OLE objects ... Hope this helps, regards, Mathias
 

pragma runLim, 10000
 
Regexp reObj = regexp "({\\\\object)|({\\\\pict)"
Regexp reBrace = regexp "([{}])"
 
Buffer b = create(); 
b = richTextWithOle (current Object)."Object Text"
 
// print tempStringOf b
 
// halt
 
int pos = 0; 
int iLen = length b
int oleStart = 0
int oleEnd   = 0 
 
Buffer result = create() 
int nextOle = -1
 
while (pos < iLen) {
   if (nextOle < pos) {
    // find the next ole object
        if ( search (reObj, b, pos) ) {
                oleStart = oleStart + start 0
                int braceLevel = 1
                oleEnd = oleStart+1
                print "Searching End of OLE from:" oleStart "\n"
                while (braceLevel > 0) {
                        if ( search (reBrace, b, oleEnd) ) {
                                string found = b[oleEnd+(start 0):oleEnd+(end 0)]
                                print "Found brace at:" (start 0) "(" found ")\n"
                                oleEnd = (end 0)+1+oleEnd
                                print "oleEnd:" (oleEnd) "-" found "\n"
                                if found == "{" then braceLevel++
                                if found == "}" then braceLevel--                          
                        } else break
                }            
                nextOle = oleStart
        } else { nextOle = iLen + 1 }
        print "Found OLE object: " oleStart "\n"
   }
   // skip ole object
   if (nextOle == pos) { 
        pos = oleEnd; continue
        print "Skipping OLE object: " oleEnd "\n"
   }
 
   // your replace code here: 
   pos ++
}

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Hey...
Your code is working so far. It finds the beginnig and the end braces but it will not enter the 'skip ole' part...
 

...
// skip ole object
if (nextOle == pos) { 
  pos = oleEnd; continue
  print "Skipping OLE object: " oleEnd "\n"
}
...

 


What can still be wrong?

THX

 

Re: identify OLE-position in object
Mathias Mamsch - Wed Oct 06 10:06:25 EDT 2010

Mr.Ferrari - Wed Oct 06 09:43:12 EDT 2010

Hey...
Your code is working so far. It finds the beginnig and the end braces but it will not enter the 'skip ole' part...
 

...
// skip ole object
if (nextOle == pos) { 
  pos = oleEnd; continue
  print "Skipping OLE object: " oleEnd "\n"
}
...

 


What can still be wrong?

THX

 

Not sure. It used to work. Can you attach the richText you are trying this with in a file and post the code you are using (if you modified it)?
 

print richTextWithOle (current Object)."Object Text"

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: identify OLE-position in object
Mathias Mamsch - Wed Oct 06 10:07:18 EDT 2010

Mr.Ferrari - Wed Oct 06 09:43:12 EDT 2010

Hey...
Your code is working so far. It finds the beginnig and the end braces but it will not enter the 'skip ole' part...
 

...
// skip ole object
if (nextOle == pos) { 
  pos = oleEnd; continue
  print "Skipping OLE object: " oleEnd "\n"
}
...

 


What can still be wrong?

THX

 

Well maybe we should move the print to before the continue :-)
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: identify OLE-position in object
Mr.Ferrari - Wed Oct 06 10:30:05 EDT 2010

Mathias Mamsch - Wed Oct 06 10:06:25 EDT 2010

Not sure. It used to work. Can you attach the richText you are trying this with in a file and post the code you are using (if you modified it)?
 

print richTextWithOle (current Object)."Object Text"

 


Regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

I did not modify the code.

I am getting an error: null buffer parameter was passed into argument position 1

argh...

Re: identify OLE-position in object
Mathias Mamsch - Wed Oct 06 16:44:14 EDT 2010

Mr.Ferrari - Wed Oct 06 10:30:05 EDT 2010
I did not modify the code.

I am getting an error: null buffer parameter was passed into argument position 1

argh...

Try being a little more specific. At what line you get the DXL error and what is your test data? Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS